/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aprendizajePorRefuerzo.interfaz;

import aprendizajePorRefuerzo.entorno.EntornoGrilla;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFormattedTextField;
import javax.swing.JTextField;

/**
 *
 * @author Fernando Sorzana
 */
public class PnlColumnas extends javax.swing.JPanel {
    
    private int numeroColumnas;
    
    private List<JFormattedTextField> textFields;

    /**
     * Creates new form PnlColumnas
     */
    public PnlColumnas() {
        initComponents();
        crearTextBox();
    }

    public int getNumeroColumnas() {
        return numeroColumnas;
    }

    public void setNumeroColumnas(int numeroColumnas) {
        this.numeroColumnas = numeroColumnas;
        crearTextBox();
    }
    
    public List<Integer> getVientos(){
        List<Integer> vientos = new ArrayList<Integer>();
        for (JFormattedTextField j : textFields){
            vientos.add((Integer)j.getValue());
        }
        return vientos;
    }

    public List<JFormattedTextField> getTextFields() {
        return textFields;
    }

    public void setTextFields(List<JFormattedTextField> textFields) {
        this.textFields = textFields;
    }
    
    private void crearTextBox(){
        GridLayout layout = new GridLayout();
        this.removeAll();
        this.setLayout(layout);
        layout.setColumns(numeroColumnas);
        layout.setRows(1);
        layout.setHgap(0);
        layout.setVgap(0);
        textFields = new ArrayList<>();
        for (int i = 0; i < numeroColumnas; i++){
            JFormattedTextField text = new JFormattedTextField();
            text.setValue(0);
            textFields.add(text);
            layout.addLayoutComponent(String.valueOf(i), text);
            this.add(text);
        }
        validate();
        repaint();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();

        setLayout(new java.awt.GridLayout(1, 0));

        jLabel1.setText("Hola");
        add(jLabel1);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables
}
